﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using StarTrek.World;

namespace StarTrek.UI.Console.MenuItem
{
    class MenuWarp : iMenuItem
    {
        #region iMenuItem Members

        public bool ProcessSomeRequest(MenuContext Menu, TextWriter sw, TextReader tr)
        {
            bool rVal = (Menu.Action == MenuAction);

            if (rVal)
            {
                //Perform Action
                Galaxy theWorld = Galaxy.Instance;
                
                sw.Write(Menu.wordWrap(Properties.Resources.MenuWarpPrompt + Properties.Resources.MenuPrompt));
                string results = tr.ReadLine();
                QuadrantPoint quad = QuadrantPoint.ParseVector(results);
                
                try
                {
                    theWorld.CurrentShip.Travel(theWorld.GetLocation(quad));
                }
                catch (InvalidFlightPath ex)
                {
                    sw.WriteLine(Menu.wordWrap(Properties.Resources.MenuWarpError));
                }
            }
            return rVal;
            
        }

        public string MenuAction
        {
            get { return "W"; }
        }

        public string Text
        {
            get { return Properties.Resources.MenuWarpText; }
        }

        public string VerboseText
        {
            get { return Properties.Resources.MenuWarpVerbose; }
        }
        #endregion
    }
}
